;2008-05-20
;Av Benjamin Ingberg och Patrik Johansson
;
;Spelare 1 och 2's styrkommandon, deras integration med resten av världen och 
;de är player som styr tiden på bomber/kraften/och vart de skall hamna

(load "character.scm")
(load "bomb.scm")
(load "animation.scm")
(load "animations.scm")

(define *normal-controls* (list 'left
                                'right
                                'up
                                'down
                                #\space))

(define *other-controls* (list #\a
                               #\d
                               #\w
                               #\s
                               #\e))

(define *no-controls* (list 'dummy
                            'dummy
                            'dummy
                            'dummy
                            'dummy))

(define player%
  (class character%
    (init x y w h sprites controls)
    (super-new [x x][y y][w w][h h][sprites sprites])
    (define key-listener (new key-listener%))
    
    (define bombcounter 0)
    (define left (car controls))
    (define right (cadr controls))
    (define up (caddr controls))
    (define down (cadddr controls))
    (define bomb (cadddr (cdr controls)))
     
    (define/override (get-type)
      'player)
    
    (define/override (die board)
      (send board add-world-object (new schemerman-death [x (send this get-x)][y (send this get-y)][board board])))
    
    (define/override (object-interaction obj board)
      (let ((type (send obj get-type)))
        (cond ((eq? type 'normal) #t)
              ((eq? type 'monster) (send board kill this)
                                   #t)
              ((eq? type 'bomb) (send obj
                                      collides?
                                      (send this get-x)
                                      (send this get-y)
                                      (send this get-w)
                                      (send this get-h)))
              ((eq? type 'wall) #f)
              (else #f))))
 ;Override funktion för hur player skall reagera med olika world-objects
    
    (define/override (update board)
      (set! bombcounter (- bombcounter 1))
      (if (send key-listener is-key-down? left)
          (send this try-move (- (send this get-x) 3) (send this get-y) board))                  
      (if (send key-listener is-key-down? right)
          (send this try-move (+ (send this get-x) 3) (send this get-y) board))        
      (if (send key-listener is-key-down? up)
          (send this try-move (send this get-x) (- (send this get-y) 3) board))        
      (if (send key-listener is-key-down? down)
          (send this try-move (send this get-x) (+ (send this get-y) 3) board))
      (if (and (send key-listener is-key-down? bomb)
               (< bombcounter 0))
          (begin (set! bombcounter 30)
                 (send board
                       add-character
                       (new bomb% [x (send this get-x)] [y (send this get-y)] [power 100])))))))
;Spelarnas tangentfunktioner